package com.culturalCenter.dataCenter.service.impl.volunteer;

import com.culturalCenter.dataCenter.customEntity.responseParam.volunteer.VolunteerActivityResponse;
import com.culturalCenter.dataCenter.entity.volunteer.CdcVolunteerActivity;
import com.culturalCenter.dataCenter.mapper.volunteer.CdcVolunteerActivityMapper;
import com.culturalCenter.dataCenter.service.volunteer.CdcVolunteerActivityService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 志愿者活动信息(CdcVolunteerActivity)表服务实现类
 *
 * @author makejava
 * @since 2021-09-17 16:10:01
 */
@Service("cdcVolunteerActivityService")
public class CdcVolunteerActivityServiceImpl implements CdcVolunteerActivityService {

    @Resource
    private CdcVolunteerActivityMapper cdcVolunteerActivityMapper;

    @Override
    public CdcVolunteerActivity queryById(String id) {
        return this.cdcVolunteerActivityMapper.queryById(id);
    }

    @Override
    public List<CdcVolunteerActivity> queryAllByLimit(int offset, int limit) {
        return this.cdcVolunteerActivityMapper.queryAllByLimit(offset, limit);
    }

    @Override
    public CdcVolunteerActivity insert(CdcVolunteerActivity cdcVolunteerActivity) {
        this.cdcVolunteerActivityMapper.insert(cdcVolunteerActivity);
        return cdcVolunteerActivity;
    }

    @Override
    public CdcVolunteerActivity update(CdcVolunteerActivity cdcVolunteerActivity) {
        this.cdcVolunteerActivityMapper.update(cdcVolunteerActivity);
        return this.queryById(cdcVolunteerActivity.getId());
    }

    @Override
    public boolean deleteById(String id) {
        return this.cdcVolunteerActivityMapper.deleteById(id) > 0;
    }

    @Override
    public VolunteerActivityResponse activityStatistics() {
        VolunteerActivityResponse activityResponse = new VolunteerActivityResponse();
        activityResponse.setActivityCount(cdcVolunteerActivityMapper.activityCount());
        activityResponse.setViewRanking(cdcVolunteerActivityMapper.getRanking(0));
        activityResponse.setCollectionRanking(cdcVolunteerActivityMapper.getRanking(1));
        activityResponse.setActivityRecommendation(cdcVolunteerActivityMapper.getRanking(2));
        return activityResponse;
    }

}
